package com.itfreer.gis.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import com.itfreer.form.api.BaseDao;
import com.itfreer.form.api.imp.DictionaryConvertServiceImp;
import com.itfreer.gis.dao.GisLayerConfigDao;
import com.itfreer.gis.entity.GisLayerConfigEntity;

@Component("gisLayerConfigServiceImp")
public class GisLayerConfigServiceImp extends DictionaryConvertServiceImp<GisLayerConfigEntity> implements GisLayerConfigService {
	
	@Autowired
	private GisLayerConfigDao gisLayerConfigDao;

	@Override
	protected BaseDao<GisLayerConfigEntity> getDao() {
		return gisLayerConfigDao;
	}
	
	/**
	 * 添加实体
	 * @param entity		添加实体
	 * @return
	 */
	@CacheEvict(value="GisLayerConfigCache", allEntries=true)
	@Override
	public GisLayerConfigEntity add(GisLayerConfigEntity entity){
		return super.add(entity);
	}
	
	/**
	 * 更新实体
	 * @param guid			唯一值
	 * @param entity		实体
	 * @return
	 */
	@CacheEvict(value="GisLayerConfigCache", allEntries=true)
	@Override
	public GisLayerConfigEntity update(GisLayerConfigEntity entity){
		return super.update(entity);
	}
	
	/**
	 * 删除实体
	 * @param guid			唯一值
	 */
	@CacheEvict(value="GisLayerConfigCache", allEntries=true)
	@Override
	public void delete(String guid){
		super.delete(guid);
	}
	
	/**
	 * 指量删除实体
	 * @param guid			唯一值集
	 */
	@CacheEvict(value="GisLayerConfigCache", allEntries=true)
	@Override
	public void deletes(String guids){
		super.deletes(guids);
	}

	@Cacheable(value="GisLayerConfigCache", key="#regService")
	@Override
	public List<GisLayerConfigEntity> getLayerConfig(String regService) {
		Map<String, Object> where = new HashMap<String, Object>();
		where.put("registerService", regService);
		
		Map<String, Integer> order = new HashMap<String, Integer>();
		order.put("index", 0);
		
		return super.getEntitys(null, where, order, 10000, 1);
	}
}